package com.ztools.pc.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.sys.Dict;
import com.ztools.common.model.pc.sys.DictData;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.common.util.pc.TokenAuthorization;
import com.ztools.pc.service.sys.DictService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:一口香菜
 * @Date: 2023/3/3  17:50
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/dict")
public class DictController {

    @Resource
    private DictService dictService;

    @RequestMapping("/list")
    @TokenAuthorization("/sys/dict/search")
    public Result findList(@RequestBody PageUtil<Dict> dict) {
        Page<Dict> list = dictService.findList(dict);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody Dict dict) {
        List<DictData> list = dictService.findByObject(dict);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody Dict dict) {
        boolean b = dictService.delete(dict);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Dict dict) {
        boolean b = dictService.save(dict);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Dict dict) {
        boolean b = dictService.update(dict);
        return b ? Result.success("修改成功") : Result.error();
    }
}
